<?php //debug($ordenesTags);   ?>
<?php 
    echo $this->Html->script(array(
        'print'
    )); 
?>
<div class="grid12">
    <div class="widget">
    <div id="areaImprimir">
        <div class="whead"><h6></h6><div class="clear"></div></div>
        <div class="body" align="left">
            <h2>PURCHASE ORDER: <?php echo $orden['Ordene']['nombre']; ?></h2>
            <h2>Descripcion: <?php echo $orden['Ordene']['descripcion']; ?></h2>
            <h2>Fecha: <?php echo $orden['Ordene']['fecha']; ?></h2>
            <br />
            &nbsp;
            <h6>UNIDAD MONETARIA:&nbsp; <?php echo $orden['Ordene']['tipo_moneda'] ?></h6>
        </div>
        
    <table cellpadding="0" cellspacing="0" width="100%" class="tAlt">
        <tr>
            <td><b>Categor&iacute;a</b></td>
            <td><?php echo $orden['Categoria']['nombre']; ?></td>
            <td><b>REVISED TOTAL</b></td>
            <td>
               <?php
                //echo $orden['Ordene']['monto']; 
                $montoPo = $orden['Ordene']['monto'];                                     
                        $modMontoPo = $this->Number->format($montoPo, array(
                            'places' => 2,
                            'before' => ' ',
                            'escape' => false,
                            'decimals' => '.',
                            'thousands' => ','
                        ));
                        echo $modMontoPo;
               ?>
            </td>
        </tr>
        <tr>
            <td><b>Volumenes</b></td>
            <td><?php echo $orden['Ordene']['volumenes']; ?></td>
            <td><b>CAF</b></td>
            <td><?php echo $orden['Ordene']['cantidadcaf']; ?></td>
        </tr>
        <tr>
            <td><b>Original</b></td>
            <td>
                <?php
                if ($orden['Ordene']['original'] == 'S')
                {
                    echo "SI";
                } else
                {
                    echo "NO";
                }
                ?>
            </td>
            <td><b>Firmas</b></td>
            <td><?php echo $orden['Ordene']['firmasoriginal']; ?></td>
        </tr>
        <tr>
            <td><b>Copia</b></td>
            <td>
                <?php
                if ($orden['Ordene']['copia'] == 'S')
                {
                    echo "SI";
                } else
                {
                    echo "NO";
                }
                ?>
            </td>
            <td><b>Firmas</b></td>
            <td><?php echo $orden['Ordene']['firmascopia']; ?></td>
        </tr>

        <tr>
            <td><b>Proveedor</b></td>
            <td colspan="3"><?php echo $orden['Ordene']['proveedor']; ?></td>
        </tr>
        <tr>
            <td><b>Descripci&oacute;n</b></td>
            <td colspan="3"><?php echo $orden['Ordene']['descripcion']; ?></td>
        </tr>
        
        <tr>
            <td><b>Caja Archivo</b></td>
            <td colspan="3"><?php echo $orden['Ordene']['lugar']; ?></td>
        </tr>
        
        <tr>
            <td><b>Observaciones</b></td>
            <td colspan="3"><?php echo $orden['Ordene']['observaciones']; ?></td>
        </tr>
    </table>
    
    <p>&nbsp;</p>
    <hr />
    <p>&nbsp;</p>
    
    <h4>Documentos</h4>    
    <table cellpadding="0" cellspacing="0" width="100%" class="tAlt">
        <thead>
            <tr>
                <th scope="col">Documento</th>                
                <th scope="col">Ubicacion (Volumen)</th>
            </tr>
        </thead>
        
        <tbody>
            <?php //debug($documentos); ?>
            <?php foreach ($documentos as $d): ?>
                <tr>
                    <td>
                        <?php 
                            echo $d['documentos']['nombre']; 
                            if(($d['doc']['documento_id'] == 15) || ($d['doc']['documento_id'] == 1))
                            {
                                if($d['doc']['original']==1)
                                {
                                    echo(' - (Original)');
                                }
                            }
                        ?>
                    </td>                    
                    <td><?php echo $d['doc']['volumen']; ?></td>                    
                </tr>
            <?php endforeach; ?>
        </tbody>        
    </table>
    
    <p>&nbsp;</p>
    <hr />
    <p>&nbsp;</p>
        
    <h4 id="btTags">TAGS (+)</h4>        
    
    <div id="muestra">
    <table cellpadding="0" cellspacing="0" width="100%" class="tAlt">
        <thead>
            <tr>
                <th scope="col">Tags</th>
                <th scope="col">Descripcion</th>
                <th scope="col">Monto</th>
            </tr>
        </thead>
        
        <tbody>
            <?php foreach ($ordenesTags as $ot): ?>
                <?php $sum = 0; ?>
                <tr>
                    <td><?php echo $ot['ot']['tag_id']; ?></td>            
                    <td>
                        <?php
                        if ($ot['tags']['descripcion1'] == NULL)
                        {
                            echo 'NO TIENE';
                        } else
                        {
                            echo $ot['tags']['descripcion1'];
                        }
                        ?>
                    </td>       
                    <td>
                        <?php //$ot['ot']['monto']; $sum += $ot['ot']['monto']; echo $sum;
                        
                        $montoTag = $ot['ot']['monto'];                                     
                        $modMontoTag = $this->Number->format($montoTag, array(
                            'places' => 2,
                            'before' => ' ',
                            'escape' => false,
                            'decimals' => '.',
                            'thousands' => ','
                        ));
                        echo $modMontoTag;
                        ?>
                    </td>
                </tr>
            <?php endforeach; ?>
        </tbody>

    </table>  
    </div>
    
    <p>&nbsp;</p>
    <hr />
    <p>&nbsp;</p>
    
    <h4>CHANGE ORDER</h4>
    <?php //debug($cambiosO); ?>
    <?php foreach($cambiosO as $c): ?>
    <?php $idCambioOrden = $c['Cambiordene']['id']; ?>
    <table cellpadding="0" cellspacing="0" width="100%" class="tAlt">
        <tr>
            <td style="width: 320px;"><h5>Numero Cambio de Orden</h5></td>
            <td><h3>000<?php echo $c['Cambiordene']['numero']; ?></h3></td>
            <td colspan="2"><b>TOTAL AMOUNT</b>
            <?php                 
                $montoCo = $c['Cambiordene']['monto']; 
                $modMontoCo = $this->Number->format($montoCo, array(
                            'places' => 2,
                            'before' => ' ',
                            'escape' => false,
                            'decimals' => '.',  
                            'thousands' => ','
                        ));
                echo $modMontoCo;
            ?>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <b>Monto Tags CO&nbsp;</b>
            <?php             
                App::import('Model', 'CambiordenesTag');
                $modeloCo = new CambiordenesTag();
                $diferenciaCo = $modeloCo->find('first', array(
                    'recursive'=>-1,
                    'fields'=>array('SUM(CambiordenesTag.monto) as monto, CambiordenesTag.cambiordene_id'),
                    'conditions'=>array('CambiordenesTag.cambiordene_id'=>$idCambioOrden)
                ));     
                
                //debug($diferenciaCo);
                $montoCamb = $diferenciaCo['0']['monto'];                                                     
                    $modMontoCamb = $this->Number->format($montoCamb, array(
                            'places' => 2,
                            'before' => ' ',
                            'escape' => false,
                            'decimals' => '.',
                            'thousands' => ','
                        ));
                 
                echo $modMontoCamb."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; 
                               
                $restaTotal = $montoCo - $montoCamb;                                     
                    $modRestaTotal = $this->Number->format($restaTotal, array(
                            'places' => 2,
                            'before' => ' ',
                            'escape' => false,
                            'decimals' => '.',
                            'thousands' => ','
                        ));
                //echo "resta total ".$modRestaTotal;
            ?>
            </td>
            <?php //echo $c['Cambiordene']['monto'];                                 
                        //echo $modMontoCord;            
            ?>            
        </tr>
        <tr>
            <td><b>Volumen</b></td>
            <td>
                <?php 
                    if(empty($c['Cambiordene']['volumen'])){
                        echo '0';
                    }else{
                        echo $c['Cambiordene']['volumen'];
                        
                    }
                    //echo $c['Cambiordene']['volumen']; 
                ?>
            </td>
            <td><b>Fecha</b></td>
            <td><?php echo $c['Cambiordene']['fecha']; ?></td>
        </tr>
        <tr>
            <td><b>Documento Original</b></td>
            <td>
                <?php
                if ($c['Cambiordene']['original'] == 1)
                {
                    echo "SI";
                } else
                {
                    echo "NO";
                }
                ?>
            </td>
            <td><b>Cantidad de Firmas</b></td>
            <td><?php echo $c['Cambiordene']['cantforiginal']; ?></td>
        </tr>
        <tr>
            <td><b>Documento Copia</b></td>
            <td>
                <?php
                if ($c['Cambiordene']['copia'] == 1)
                {
                    echo "SI";
                } else
                {
                    echo "NO";
                }
                ?>

                <?php //echo $c['Cambiordene']['copia']; ?>
            </td>
            <td><b>Cantidad de Firmas</b></td>
            <td><?php echo $c['Cambiordene']['cantfcopia']; ?></td>
        </tr>
        <tr>
            <td><b>Observaciones</b></td>
            <td colspan="3"><?php echo $c['Cambiordene']['observaciones']; ?></td>
        </tr>        
    </table>        
        
    <div style="text-decoration: underline; cursor: hand; font-weight: bolder;" id="btTags_<?php echo $idCambioOrden; ?>" title="Mostrar Tags">TAGS (+)</div>
    <div id="muestratags_<?php echo $idCambioOrden; ?>">
    </div> 
    <p>&nbsp;</p>
    <hr />
    <p>&nbsp;</p>       
    <script>

        
        $('#muestratags_<?php echo $idCambioOrden; ?>').hide();        
        
        $('#btTags_<?php echo $idCambioOrden; ?>').click(function() {
            $('#muestratags_<?php echo $idCambioOrden; ?>').load('../ajaxmuestratagsco/<?php echo $idCambioOrden; ?>'); 
            $('#muestratags_<?php echo $idCambioOrden; ?>').toggle('slow');                     
        });
    </script>
    <?php endforeach; ?>
     
</div>
  </div>
    </div> 
    
   <div class="grid12">
    <div class="widget">
                        <div class="whead"><h6>Acciones</h6><div class="clear"></div></div>
                        <div class="body" align="center">
                            <?php //echo $this->Html->link("Volver &raquo;", array('controller'=>'Publicos', 'action'=>'generales'), array('class'=>'buttonS bLightBlue', 'escape' => FALSE)); ?>
                            <a href="javascript:history.go(-1)" class="buttonS bLightBlue">Atras</a>
                            <input type="button" class="buttonS bGreen" value="Imprimir" id="btnImprimir" />
                        </div>
    </div>
   </div>
<script type="text/javascript">
   $(document).ready(function() {

         $("#btnImprimir").click(function() {
            //console.log('click');
             printElem({ leaveOpen: true, printMode: 'popup' });
             printElem({ overrideElementCSS: ['../../css/styles.css'] });
         });
         
        $('#muestra').hide();        
        
        $('#btTags').click(function() {
            $('#muestra').toggle('slow');
            /*$('#fbalumno').hide('slow');
            $('#fbprofesor').hide('slow');  
            $('#fbusuario').hide('slow');*/                      
        });  
                      

     });
 function printElem(options){
     $('#areaImprimir').printElement(options);
 }

 </script>


